package cn.cttic.base.dubbo;

import cn.cttic.base.api.RemoteBaseRecordService;
import cn.cttic.base.api.domain.bo.BaseRecordBo;
import cn.cttic.base.api.domain.vo.BaseRecordVo;
import cn.cttic.base.service.IBaseRecordService;
import cn.cttic.common.core.exception.base.BaseException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.List;

@DubboService
@RequiredArgsConstructor
@Slf4j
public class RemoteBaseRecordServiceImpl implements RemoteBaseRecordService {

    private final IBaseRecordService baseRecordService;

    /**
     * 添加设备信息
     *
     * @param bo@return
     */
    @Override
    public BaseRecordVo addRecord(BaseRecordBo bo) {
        if (baseRecordService.insertByBo(bo)) {
            return baseRecordService.queryById(bo.getId());
        }
        throw new BaseException("添加记录失败！");
    }

    /**
     * 根据三方的设备标识查询设备信息
     *
     * @param businessId 业务ID
     * @return
     */
    @Override
    public List<BaseRecordVo> getRecordList(String businessId) {
        BaseRecordBo bo = new BaseRecordBo();
        bo.setBusinessId(businessId);
        List<BaseRecordVo> list = baseRecordService.queryList(bo);
        return list;
    }

    /**
     * 根据IMEI查询设备标识信息
     *
     * @param businessId 业务ID
     * @param actionType 操作类型
     * @return
     */
    @Override
    public List<BaseRecordVo> getRecordList(String businessId, String actionType) {
        BaseRecordBo bo = new BaseRecordBo();
        bo.setBusinessId(businessId);
        bo.setActionType(actionType);
        List<BaseRecordVo> list = baseRecordService.queryList(bo);
        return list;
    }
}
